package com.example.prison.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.prison.entity.MapInfo;
import com.example.prison.mapper.AreaManagementMapper;
import com.example.prison.service.MapInfoService;
import com.example.prison.mapper.MapInfoMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author jiang
* @description 针对表【map_info】的数据库操作Service实现
* @createDate 2023-05-30 11:29:22
*/
@Service
public class MapInfoServiceImpl extends ServiceImpl<MapInfoMapper, MapInfo>
    implements MapInfoService{

    @Autowired
    private MapInfoMapper mapInfoMapper;

    @Autowired
    private AreaManagementMapper areaManagementMapper;

    @Override
    public PageInfo<MapInfo> get(int pageNumber, int pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        return new PageInfo<>(mapInfoMapper.get());
    }

    @Override
    public int add(MapInfo map) {
        if(ObjectUtils.isNotEmpty(mapInfoMapper.get())) {
            MapInfo mapDTO = mapInfoMapper.getOne();
            mapInfoMapper.deleteMapById(mapDTO.getId());
            areaManagementMapper.deleteAll();
        }
        mapInfoMapper.add(map);
        return 1;
    }

    @Override
    public void delete(Integer[] ids) {
        areaManagementMapper.deleteAll();
        mapInfoMapper.deleteMap(ids);
    }

}




